// Copyright Epic Games, Inc. All Rights Reserved.

#pragma once

#include "CoreMinimal.h"
#include "SmartMenu.generated.h"

/** 菜单类型枚举 */
UENUM(BlueprintType)
enum class EMenuItemType : uint8
{
	Separator         UMETA(DisplayName = "Separator"),
	Action       UMETA(DisplayName = "Action"),
	Menu      UMETA(DisplayName = "Menu"),
	BeginSection      UMETA(DisplayName = "BeginSection"),
	EndSection      UMETA(DisplayName = "EndSection"),
};

// 菜单项基类
UCLASS(Blueprintable)
class USmartMenuItemBase : public UObject
{
	GENERATED_BODY()

protected:
	EMenuItemType Type;
public:
	UFUNCTION(BlueprintCallable, Category = Python)
	EMenuItemType GetType() { return Type; };
};

// 菜单开始段项
UCLASS(Blueprintable)
class USmartBeginSection : public USmartMenuItemBase
{
	GENERATED_BODY()
	USmartBeginSection() {
		Type = EMenuItemType::BeginSection;
		Name = FString("New Section");
	}
public:
	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = Python)
	FString Name;
};

// 菜单结束段项
UCLASS(Blueprintable)
class USmartEndSection : public USmartMenuItemBase
{
	GENERATED_BODY()
	USmartEndSection() {
		Type = EMenuItemType::EndSection;
	}
};

// 菜单分割项
UCLASS(Blueprintable)
class USmartSeparator : public USmartMenuItemBase
{
	GENERATED_BODY()
		USmartSeparator() {
		Type = EMenuItemType::Separator;
	}
};

// 菜单动作项
UCLASS(Blueprintable)
class USmartAction : public USmartMenuItemBase
{
	GENERATED_BODY()
	USmartAction() {
		Type = EMenuItemType::Action;
		Name = FString("New Action");
	};
public:
	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = Python)
	FString Name;

	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = Python)
	bool bIsWrapper=false;
	
	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = Python)
	FString Description;

	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = Python)
	FString Command;
	
	UFUNCTION(BlueprintImplementableEvent, Category = Python)
	void ExecuteCommand() const;
	
};

// 菜单项
UCLASS(Blueprintable)
class USmartMenu : public USmartMenuItemBase
{
	GENERATED_BODY()
	USmartMenu() {
		Type = EMenuItemType::Menu;
		Name = FString("New Menu");
	};
public:
	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = Python)
	FString Name;

	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = Python)
	FString Description;

	TArray<USmartMenuItemBase*> Items;

	UFUNCTION(BlueprintCallable, Category = Python)
	USmartAction* AddAction(USmartAction* InAction = nullptr, const FString& InName = "New Action", const FString& InCommand = "", const FString& InDescription = "");

	UFUNCTION(BlueprintCallable, Category = Python)
	USmartAction* InsertAction(int32 Index, USmartAction* InAction = nullptr, const FString& InName = "New Action", const FString& InCommand = "", const FString& InDescription = "");

	UFUNCTION(BlueprintCallable, Category = Python)
	int32 ActionCount();
	
	UFUNCTION(BlueprintCallable, Category = Python)
	USmartMenu* AddMenu(USmartMenu* InMenu = nullptr, const FString& InName = "New Menu", const FString& InDescription = "");

	UFUNCTION(BlueprintCallable, Category = Python)
	void AddSeparator(USmartSeparator* InSeparator = nullptr);

	UFUNCTION(BlueprintCallable, Category = Python)
	USmartBeginSection* AddBeginSection(USmartBeginSection* InBeginSection = nullptr, const FString& InName = "New Section");

	UFUNCTION(BlueprintCallable, Category = Python)
	void AddEndSection(USmartEndSection* InEndSection = nullptr);
};
